package com.fishv.fishvdianping.controller;

import com.fishv.fishvdianping.common.ErrorCode;
import com.fishv.fishvdianping.common.Result;
import com.fishv.fishvdianping.model.domain.Shop;
import com.fishv.fishvdianping.service.ShopService;
import com.fishv.fishvdianping.utils.ThrowUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yuwei
 * @date 23:06 2024/10/20
 */
@RestController
@RequestMapping("/shop")
public class ShopController {

    @Resource
    private ShopService shopService;

    @GetMapping("/{id}")
    public Result getShopById(@PathVariable("id") Long id) {
        ThrowUtils.throwIf(id == null, ErrorCode.PARAMS_ERROR, "id不能为空");
        return Result.ok(shopService.getById(id));
    }

   @PostMapping("/update")
    public Result update(@RequestBody Shop shop) {
        Long id = shop.getId();
        ThrowUtils.throwIf(id == null, ErrorCode.PARAMS_ERROR, "id不能为空");
        return Result.ok(shopService.update(shop));
    }
}
